package com.itheima.health.job;


import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.date.DateUtils;

import org.apache.dubbo.config.annotation.Reference;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;
import java.util.Date;

public class QuartzDemo implements Job {
    @Autowired
    private OrderSettingService orderSettingService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        //获取当前时间
        Date date = new Date();
        //创建Calendar
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        //calendar.add(Calendar.YEAR,-2);
        calendar.add(Calendar.YEAR,-1);
        date = calendar.getTime();
        String strdate = null;
        try {
            strdate = DateUtils.parseDate2String(date);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println(strdate);
        Boolean flag = orderSettingService.deleteForQuartz(strdate);
        if(flag){
            System.out.println("清除过期数据成功！");
        }else{
            System.out.println("清除过期数据失败！");
        }

    }
}
